<?php


use Laravel\CLI\Tasks\Bundle\Publisher;

class Admin_Membership_Controller extends Admin_Controller
{

	public $restful = true;


	public function __construct()
	{
		parent::__construct();
		//--Your Code --//
		$this->theme->set_theme("admin");

	}

	public function get_add(){
		 
		$this->theme->title("Membership Plan Add");
		return $this->theme->render('admin::membership.add');
		 
	}

	public function post_add(){
		 
		$rules = array(
				'plan_title' => 'required',
				'plan_description' => 'required',
				'keyword_limit' => 'required',
				'period' => 'required'
		);
		 
		$validator = Validator::make(Input::get(), $rules);
		if( $validator->fails() )
		{
			return Redirect::back()->with_input()->with_errors($validator)->with('message','<div class="alert alert-danger">Invalid Operation !</div>');
		}
		else
		{

			$post_data = array(

					'name' => Input::get('plan_title'),
					'period' => Input::get('period'),
					'description' => Input::get('plan_description'),
					'contact_no' => (int) Input::get('contact_no'),
					'contact_person' => (int) Input::get('contact_person'),
					'email' => (int) Input::get('email'),
					'website' => (int) Input::get('website'),
					'video' => (int) Input::get('video'),
					'photo' => (int) Input::get('photo'),
					'products' => (int) Input::get('products'),
					'keyword_limit' => Input::get('keyword_limit'),
					'photo_limit' => Input::get('photo_limit'),
					'products_limit' => Input::get('products_limit'),
					'price' => Input::get('price'),

			);

			DB::table('membership')->insert($post_data);


			return Redirect::back()->with_input()->with_errors($validator)->with('message','<div class="alert alert-info">Successfully Added</div>');
		}
		 
	}

	public function get_edit($mID){
		 
		 $data['membership'] = DB::table('membership')->where('id','=',$mID)->first();
		 
		$this->theme->title("Edit Membership");
		return $this->theme->render('admin::membership.edit',$data);
		 
		 
	}
	
	public function post_edit(){
		
		$rules = array(
				'plan_title' => 'required',
				'plan_description' => 'required',
				'keyword_limit' => 'required',
				'period' => 'required'
		);
			
		$validator = Validator::make(Input::get(), $rules);
		
		$thisOrderid = Input::get('memID');
		if( $validator->fails() )
		{
			return Redirect::back()->with_input()->with_errors($validator)->with('message','<div class="alert alert-danger">Invalid Operation !</div>');
		}
		else
		{
		
			$post_data = array(
		
					'name' => Input::get('plan_title'),
					'period' => Input::get('period'),
					'description' => Input::get('plan_description'),
					'contact_no' => Input::get('contact_no'),
					'contact_person' => Input::get('contact_person'),
					'email' => Input::get('email'),
					'website' => Input::get('website'),
					'video' => Input::get('video'),
					'photo' => Input::get('photo'),
					'products' => Input::get('products'),
					'keyword_limit' => Input::get('keyword_limit'),
					'photo_limit' => Input::get('photo_limit'),
					'products_limit' => Input::get('products_limit'),
					'price' => Input::get('price'),
		
			);
		
			DB::table('membership')->where('id','=',$thisOrderid)->update($post_data);
		
		
			return Redirect::back()->with_input()->with_errors($validator)->with('message','<div class="alert alert-info">Successfully Updated</div>');
		}
		
		
	}

	
	public function get_delete($mID){
		
		DB::table('membership')->where('id','=',$mID)->delete();
		return Redirect::to('/admin/membership/add');
		
	}

}